package com.lsj.ssmTest.service.impl;

import com.lsj.ssmTest.core.exception.LoginException;
import com.lsj.ssmTest.mapper.UserMapper;
import com.lsj.ssmTest.model.User;
import com.lsj.ssmTest.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Lsj
 * @version 1.0
 * @date 2021/6/29 11:35
 */
@Service
@AllArgsConstructor
public class UserServiceImpl implements IUserService {
    private final UserMapper userMapper;

    /**
     * 查找
     *
     * @param user 查询列表
     * @return 无
     */
    @Override
    public List<User> list(User user) {
        return userMapper.list(user);
    }

    /**
     * 登录
     *
     * @param username 用户名
     * @param password 密码
     * @return 用户
     */
    @Override
    public User login(String username, String password) throws LoginException {
        User user = userMapper.selectByUsername(username);
        if (user == null) {
            throw new LoginException("用户不存在");
        }
        if (!password.equals(user.getPassword())) {
            throw new LoginException("密码错误");
        }
        return user;
    }


}
